package com.ruoyi.graduate.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.graduate.domain.param.MsCarouselAddParam;
import com.ruoyi.graduate.domain.param.MsCarouselPageParam;
import com.ruoyi.graduate.domain.param.MsCarouselUpdataParam;
import com.ruoyi.graduate.service.IMsCarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * 轮播图控制接口
 */
@RestController
@RequestMapping("/api/carousel")
@Api(tags = "轮播图控制接口")
public class MsCarouselController extends BaseController {

    @Autowired
    private IMsCarouselService msCarouselService;


    @ApiOperation("轮播图分页查询")
    @GetMapping
    public TableDataInfo listPage(MsCarouselPageParam param) {

        PageInfo pageInfo = msCarouselService.lisstPage(param);

        return getDataTable(pageInfo.getList(), pageInfo.getTotal());
    }


    @ApiOperation("轮播图新增")
    @PostMapping
    public AjaxResult addCarousel(@RequestBody MsCarouselAddParam param) {

        return msCarouselService.addCarousel(param);
    }


    @ApiOperation("轮播图修改")
    @PutMapping
    public AjaxResult updataCarousel(@RequestBody MsCarouselUpdataParam param) {

        return msCarouselService.updateCarousel(param);
    }


    @ApiOperation("轮播图删除")
    @DeleteMapping("{id}")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult deleteCarousel(@PathVariable Integer id) {

        boolean b = msCarouselService.removeById(id);

        return b ? AjaxResult.success() : AjaxResult.error();
    }


    @ApiOperation("用户端首页轮播图查询")
    @GetMapping("/homeList")
    public AjaxResult homeList() {

        return msCarouselService.homeVo();
    }
}
